package com.tview.visual;

public class Spectrum {


    static int VLC_FOURCC_B(byte a, byte b, byte c, byte d) {
        int value;
//        value = (int) ( ((a & 0xFF)<<24)
//                |((b & 0xFF)<<16)
//                |((c & 0xFF)<<8)
//                |(d & 0xFF));

        value = (int) ((a&0xFF)
                | ((b<<8) & 0xFF00)
                | ((c<<16)& 0xFF0000)
                | ((d<<24) & 0xFF000000));
        return value;
    }

    private static int VLC_FOURCC(char u, char b, char c, char d) {
        return VLC_FOURCC_B((byte) u,(byte) b,(byte) c,(byte) d);
    }

    private static int VLC_CODEC_S8 = VLC_FOURCC('s', '8',  ' ',  ' ');
    private static int VLC_CODEC_U8 = VLC_FOURCC('u', '8', ' ', ' ');
    private static int VLC_CODEC_S16L = VLC_FOURCC('s', '1', '6', 'l');
    private static int VLC_CODEC_S16L_PLANAR = VLC_FOURCC('s', '1', 'l', 'p');
    private static int VLC_CODEC_S16B = VLC_FOURCC('s', '1', '6', 'b');
    private static int VLC_CODEC_U16L = VLC_FOURCC('u', '1', '6', 'l');
    private static int VLC_CODEC_U16B = VLC_FOURCC('u', '1', '6', 'b');
    private static int VLC_CODEC_S20B = VLC_FOURCC('s', '2', '0', 'b');
    private static int VLC_CODEC_S24L = VLC_FOURCC('s', '2', '4', 'l');
    private static int VLC_CODEC_S24B = VLC_FOURCC('s', '2', '4', 'b');
    private static int VLC_CODEC_U24L = VLC_FOURCC('u', '2', '4', 'l');
    private static int VLC_CODEC_U24B = VLC_FOURCC('u', '2', '4', 'b');
    private static int VLC_CODEC_S24L32 = VLC_FOURCC('s', '2', '4', '4');
    private static int VLC_CODEC_S24B32 = VLC_FOURCC('S', '2', '4', '4');
    private static int VLC_CODEC_S32L = VLC_FOURCC('s', '3', '2', 'l');
    private static int VLC_CODEC_S32B = VLC_FOURCC('s', '3', '2', 'b');
    private static int VLC_CODEC_U32L = VLC_FOURCC('u', '3', '2', 'l');
    private static int VLC_CODEC_U32B = VLC_FOURCC('u', '3', '2', 'b');
    private static int VLC_CODEC_F32L = VLC_FOURCC('f', '3', '2', 'l');
    private static int VLC_CODEC_F32B = VLC_FOURCC('f', '3', '2', 'b');
    private static int VLC_CODEC_F64L = VLC_FOURCC('f', '6', '4', 'l');
    private static int VLC_CODEC_F64B = VLC_FOURCC('f', '6', '4', 'b');


    public static int VLC_CODEC_S16N = VLC_CODEC_S16L;
    public static int VLC_CODEC_U16N = VLC_CODEC_U16L;
    public static int VLC_CODEC_S24N = VLC_CODEC_S24L;
    public static int VLC_CODEC_U24N = VLC_CODEC_U24L;
    public static int VLC_CODEC_S32N = VLC_CODEC_S32L;
    public static int VLC_CODEC_U32N = VLC_CODEC_U32L;
    public static int VLC_CODEC_FL32 = VLC_CODEC_F32L;
    public static int VLC_CODEC_FL64 = VLC_CODEC_F64L;

//    public static int VLC_CODEC_S16I = VLC_CODEC_S16B;
//    public static int VLC_CODEC_U16I = VLC_CODEC_U16B;
//    public static int VLC_CODEC_S24I = VLC_CODEC_S24B;
//    public static int VLC_CODEC_U24I = VLC_CODEC_U24B;
//    public static int VLC_CODEC_S32I = VLC_CODEC_S32B;
//    public static int VLC_CODEC_U32I = VLC_CODEC_U32B;



//    private static int VLC_FOURCC(char s, char b, char c, char d) {
//
//        return 0;
//    }

    static {
        System.loadLibrary("visual");
    }

    private long mInstance = 0;

    public Spectrum(int channel, int branc_80, int formate) {
        NewInstance(channel, branc_80, formate);
    }

    public int pushData(byte[] bytes,int sample,int[] ints){
        return nativSetPCM(bytes, sample,ints);
//        return 0;
    }

    public void Release() {
        nativeRelease();
    }

    @Override
    protected void finalize() throws Throwable {
        nativeRelease();
        mInstance = 0;
        super.finalize();
    }

    private native void NewInstance(int channel, int branc_80, int formate);

    private native int nativSetPCM(byte[] data, int sample,int[] ints);

    private native void nativeRelease();
}
